package com.changzhi.common.task;

import com.changzhi.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommonTask {

    @Autowired
    private OrderDayService orderDayService;
    @Autowired
    private UserGiftDayService userGiftDayService;
    @Autowired
    private WeekStarService weekStarService;
    @Autowired
    private SignService signService;
    @Autowired
    private TanabataService tanabataService;
    @Autowired
    private InviteService inviteService;

    @Autowired
    private RedService redService;

    /**
     * 修复订单
     */
    @Scheduled(cron = "0 0 */2 * * ?")
    public void repairOrder() {
        orderDayService.repairOrder(null, null);
    }

    /**
     * 修复天礼物
     */
    @Scheduled(cron = "0 50 0 * * ?")
    //@Scheduled(cron = "0 6 */4 * * ?")
    public void repairGiftDay() {
        userGiftDayService.repairGiftDay(null, null);
    }

    /**
     * 相差礼物值
     */
    @Scheduled(cron = "0 0/40 * * * ? ")
    public void differGiftValue() {
        userGiftDayService.differGiftValue();
    }

    /**
     * 周星榜发送奖励
     */
    @Scheduled(cron = "0 2 0 12 7 ?")
    public void givePrize() {
        log.error("=====1");
        weekStarService.givePrize();
        log.error("=====2");
    }

    /**
     * 星座物语发送奖励
     */
    @Scheduled(cron = "0 2 0 23 8 ?")
    public void signGivePrize() {
        log.error("=====3");
        signService.givePrize();
        log.error("=====4");
    }

    /**
     * 七夕心动之约发送奖励
     */
    @Scheduled(cron = "0 2 0 12,13,14,15,16,17,18 8 ?")
    public void tanabataGivePrize() {
        log.error("=====5");
        tanabataService.givePrize();
        log.error("=====6");
    }

//    @Scheduled(cron = "0 0 19,22 28,29,30,31,1,2,3 1,2 ?")
//    @Scheduled(cron = "0 0/5 13,14,15,16,17,18,19,20 21,22,23,24,25,26,27,28,29 1 ?")
    public void jobTask() {
        log.error("=====21");
        redService.jobTask();
        log.error("=====22");
    }


    /**
     * 邀请活动邀请奖励（没5分钟结算一次）
     */
    @Scheduled(cron = "40 0/5 * * * ? ")
    public void inviteGivePrize() {
        long l = System.currentTimeMillis();
        log.info("=====inviteGivePrize定时任务开始=====");
        inviteService.inviteGivePrize();
        log.info("=====inviteGivePrize定时任务开始=====,time={}", System.currentTimeMillis() - l);
    }


}
